<!--  -->
<template>
  <a-select v-model="curr" @change="handleChange">
    <a-select-option v-for="(item,index) in options" :key="index" :value="item.category_id">
      {{ item.category_name }}
    </a-select-option>
  </a-select>
</template>

<script>
import { fetchCategoryList } from '../../api/manage'

export default {
  props: {
    value: {
      type: String,
      default: ''
    },
  },
  data () {
    return {
      curr: '',
      options: []
    }
  },
  components: {

  },
  mounted () {
    this.fetchCategoryList()
  },
  methods: {
    handleChange (v) {
      console.log(v, 'v')
      this.$emit('changes', this.options.filter(item => item.category_id == v)[0])
    },
    fetchCategoryList () {
      const data = {
        page_size: 1000,
        page_no: 1,
        category_name: ''
      }
      fetchCategoryList(data).then(res => {
        console.log(res)
        this.options = res.data.infos
      }).catch(() => {
      })
    }
  },
  watch: {
    value (v) {
      this.curr = v
    }
  }
}
</script>

<style lang='less' scoped>
</style>
